//
//  Global.h
//  omni
//
//  Created by Phuong Dinh Le on 1/25/13.
//  Copyright (c) 2013 StarPound. All rights reserved.
//

#import <Foundation/Foundation.h>

//////////////////////////////////////////////////
#pragma mark - Thread maro definition
#define THREAD_TIMEOUT 5.0f


//////////////////////////////////////////////////
typedef enum
{
    ThreadRun = 0,
    ThreadPause,
    ThreadFilter,
    ThreadStop
} ThreadStatus;

typedef enum ScreenName
{
    ScreenNameNone = 0,
    ScreenNameHomeController,
    ScreenNameTransactionBookController,
    ScreenNameLoanController,
    ScreenNameDebtController,
    ScreenNameHuiSummaryController,
    ScreenNameChartController,
    ScreenNameSettingViewController,
} ScreenName;

typedef enum
{
    BarButtonSave,
    BarButtonClose,
    BarButtonUpdate,
    BarButtonDone,
    BarButtonBadge,
    BarButtonBack,
    BarButtonMenu
}BarButton;

typedef enum
{
    TransactionTypeIncomeMain = 0,
    TransactionTypeIncomeLoan,
    TransactionTypeIncomeDebt,
    TransactionTypeIncomeHui,
    TransactionTypeExpensePermanent,
    TransactionTypeExpenseNonpermanent,
    TransactionTypeExpenseLoan,
    TransactionTypeExpenseDebt,
    TransactionTypeExpenseHui
    
}TransactionType;

//Use for Cell that want to switch between input new item or select a value from a list
typedef enum
{
    TextFieldInputModeKeyboard,
    TextFieldInputModeTableView
}TextFieldInputMode;

typedef enum
{
    RepeatTypeNone,
    RepeatTypeDaily,
    RepeatTypeWeekly,
    RepeatTypeEach2Week,
    RepeatTypeMonthly
}RepeatType;

#define MENU_ITEM_COUNT ScreenNameSettingViewController

#define HEI_CELL_DEFAULT 50
#define HEI_CELL_MENU 60
#define HEI_CELL_NOTE 100
#define HEI_SECTION 50
#define HEI_KEYBOARD 216

#define PADDING 12
#define PADDING_SMALL 8
#define PADDING_TITLE_DESCRIPTION 0

//////////////////////////////////////////////////
#pragma mark - Device macro
#define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON )
#define IS_IPHONE ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPhone" ] )
#define IS_IPOD   ( [ [ [ UIDevice currentDevice ] model ] isEqualToString: @"iPod touch" ] )
#define IS_IPHONE_5 ( IS_IPHONE && IS_WIDESCREEN )
#define IS_IPAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
#define IS_PORTRAIT ( UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) )
#define DEVICE_ORIENTATION [[UIApplication sharedApplication] statusBarOrientation]
#define IS_PHONE ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)

#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define __SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_70  SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(iOS_7_0)

#define iOS_7_0 @"7.0"
#define iOS_6_0 @"6.0"


#define NAME_KEY @"name"
#define TYPE_KEY @"type"
#define PRICE_KEY @"price"
#define DESCRIPTION_KEY @"guide"
#define CATALOG_KEY @"catalog"
#define ACCOUNT_KEY @"account"
#define HUI_DETAIL_KEY @"huiDetail"
#define TRANSACTION_KEY @"transaction"
#define TRANSACTION_TEMP_KEY @"transactionTemp"
#define END_DATE_KEY @"endDate"
#define SO_KY_KEY @"soKy"
#define SO_PHAN_CHOI_KEY @"soPhanChoi"
#define SO_TIEN_HOT_KEY @"soTienHot"
#define SO_TIEN_MOI_PHAN_KEY @"soTienMoiPhan"
#define START_DATE_KEY @"startDate"
#define CREATED_DATE_KEY @"createdDate"
#define IS_EXPENSE_KEY @"isExpense"
#define NOTE_KEY @"note"
#define ROOT_PRICE_KEY @"rootPrice"
#define NOTIFICATION_KEY @"notification"
#define LAST_REPEATED_DATE_KEY @"lastRepeatedDate"

#define ACCOUNT_ENITY @"Account"
#define CATALOG_ENITY @"Catalog"
#define HUI_DETAIL_ENTITY @"HuiDetail"
#define NOTIFICATION_ENTITY @"Notification"
#define TRANSACTION_ENTITY @"Transaction"
#define TRANSACTION_TEMP_ENTITY @"TransactionTemp"

#define REPEAT_NO NSLocalizedString(@"Không", nil)
#define REPEAT_DAILY NSLocalizedString(@"Mỗi ngày", nil)
#define REPEAT_WEEKLY NSLocalizedString(@"Mỗi tuần", nil)
#define REPEAT_EACH_2_WEEK NSLocalizedString(@"Mỗi 2 tuần", nil)
#define REPEAT_MONTHLY NSLocalizedString(@"Mỗi tháng", nil)

//////////////////////////////////////////////////
#pragma mark - Font
#define FONT_BOLD(__x__) [UIFont boldSystemFontOfSize:__x__]
#define FONT(__x__) [UIFont systemFontOfSize:__x__]
#define FONT_HELVETICANEUE_BOLD(__x__) [UIFont fontWithName:@"HelveticaNeue-Bold" size:__x__]
#define FONT_HELVETICANEUE_ITALIC(__x__) [UIFont fontWithName:@"HelveticaNeue-Italic" size:__x__]
#define FONT_HELVETICANEUE(__x__) [UIFont fontWithName:@"HelveticaNeue" size:__x__]
#define FONT_HELVETICANEUE_CONDENSED_BOLD(__x__) [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:__x__]

#define FONT_SIZE_TITLE 18
#define FONT_SIZE_NORMAL 14
#define FONT_SIZE_DESCRIPTION 10

//////////////////////////////////////////////////
#pragma mark - Color
#define COLOR_HEX_ALPHA(rgbValue,alphaValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]

#define COLOR_HEX(rgbValue) COLOR_HEX_ALPHA(rgbValue,1)

#define COLOR(__r__, __g__, __b__, __a__)    [UIColor colorWithRed:__r__*1.0/255.0 green:__g__*1.0/255.0 blue:__b__*1.0/255.0 alpha:__a__*1.0]

//Colors
#define COLOR_GRAY_LIGHT COLOR(181, 181, 181, 1)
#define COLOR_GRAY_DARK COLOR(168, 171, 162, 1)
#define COLOR_WHITE_PURE [UIColor whiteColor]
#define COLOR_WHITE_DARK COLOR(237, 237, 237, 1)
#define COLOR_GRAY COLOR(142, 142, 147, 1)
#define COLOR_BLUE_IOS_7 COLOR_HEX(0x268EFF)
#define COLOR_BLUE_DARK COLOR(14, 102, 165, 1)
#define COLOR_BLUE_LIGHT_IOS_7 COLOR_HEX(0x3CAAFF)
#define COLOR_RED COLOR(254, 59, 49, 1)
#define COLOR_RED_DARK COLOR(162, 26, 57, 1)
#define COLOR_RED_PURE [UIColor redColor]
#define COLOR_GREEN COLOR(76, 217, 99, 1)
#define COLOR_GREEN_DARK COLOR(30, 147, 169, 1)
#define COLOR_BLACK_PURE [UIColor blackColor]
#define COLOR_BLACK_LIGHT COLOR(57, 57, 57, 1)
#define COLOR_ORANGE COLOR(254, 203, 46, 1)
#define CALLOUTVIEW_BACKGROUND_COLOR COLOR_HEX_ALPHA(0x000000,0.7)//0, 0, 0, 0.7)
#define CALLOUTVIEW_BORDER_COLOR COLOR_HEX(0xA7A7A7)//161, 167, 167, 1)

#define RADIAN(__degree__)  M_PI*__degree__/180

#define RECT(__x__, __y__, __w__, __h__) CGRectIntegral(CGRectMake(__x__, __y__, __w__, __h__))
#define RECT2(frame) CGRectIntegral(frame)

#define DEFAULT_ANIMATION_VECLOCITY 1400
#define SLIDING_SLOWEST_SPEED_TIME 0.4

//Dimension
#define SCREEN_SIZE [UIScreen mainScreen].bounds.size //point
#define HEI_HEADER_VIEW 44
#define HEI_STATUS_BAR 20

#define ANIMATE_DETAIL_WI 0.25f

#define MAX_LINES_OF_CHAT_MESSAGE 2
#define MAX_LINES_OF_TWEET_MESSAGE 4

#define ALPHA_DEFAULT_CELL 0.2
#define ALPHA_SELECTED_CELL 0.4
#define ALPHA_LAYER_CELL 0.4
#define ALPHA_SELECTEDLAYER_CELL 0.6
#define ALPHA_DEFAULT_TOOLBAR 0.2

//////////////////////////////////////////////////
#pragma mark - General parameters

//////////////////////////////////////////////////

#define LOG_LEVEL_OFF     0
#define LOG_LEVEL_ERROR   1
#define LOG_LEVEL_WARN    2
#define LOG_LEVEL_INFO    3
#define LOG_LEVEL_DEBUG   4
#define LOG_LEVEL_ALL     9999

#define __LOG_LEVEL__   LOG_LEVEL_INFO

extern NSString const *logLevels[];
void NSLogWithLevel(NSUInteger logLevel, NSString *format, ...);


